<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改得分主')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-main-edit" th:object="${scoreMain}">
            <input name="id" th:field="*{id}" type="hidden">
            <input name="deptId"  type="hidden"  th:field="*{deptId}" id="treeId"/>
            <div class="form-group">    
                <label class="col-sm-3 control-label">组织编号：</label>
                <!--<div class="col-sm-8">
                    <input name="deptId" th:field="*{deptId}" class="form-control" type="text">
                </div>-->
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" id="treeName" th:value="${dept.deptName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">网格员编号：</label>
                <div class="col-sm-8">
                    <!--<input name="userId" th:field="*{userId}" class="form-control" type="hidden">-->
                    <select name="userId" id="userId" class="form-control m-b" >
                        <option th:value="${user.userId}" th:text="${user.userName}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">总得分：</label>
                <div class="col-sm-8">
                    <input name="totalScore" th:field="*{totalScore}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">得分批次号：</label>
                <div class="col-sm-8">
                    <input name="scoreNumber" th:field="*{scoreNumber}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">得分时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="scoreTime" th:value="${#dates.format(scoreMain.scoreTime, 'yyyy-MM-dd HH:mm:ss')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/scoreMain";
        $("#form-main-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-main-edit').serialize());
            }
        }

        /* 用户管理-修改-选择部门树 */
        function selectDeptTree() {
            var deptId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);

            let deptId = $('#treeId').val();
            //发送ajax来获取该组织的用户
            /*deptId: 103
            parentId: 101*/
            $.ajax({
                url:ctx + 'system/user/findUserListByDeptId',
                type:'get',
                data:{deptId:deptId},
                success:function (res) {
                    console.log(res);
                    $('#userId').empty();
                    if(res.code == 0){
                        //将该用户循环到select 中
                        // <option value=""></option>
                        let data = res.data;
                        data.map((val)=>{
                            console.log(val);
                            $('#userId').append(`<option value="${val.userId}">${val.userName}</option>`);
                        })
                    }else {
                        $('#userId').append(`<option value="">无</option>`);
                    }
                }
            })
        }

        $("input[name='scoreTime']").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            autoclose: true
        });
    </script>
</body>
</html>